import 'package:flutter/material.dart';

class MySpinner<T> extends StatelessWidget {
  final List<T> items;
  final T? value;
  final Function(T?)? onChanged;
  const MySpinner({required this.items, super.key, this.value, this.onChanged});

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: DropdownButtonFormField<T>(
        isExpanded: true,
        initialValue: value,
        decoration: InputDecoration(
          contentPadding: EdgeInsets.symmetric(horizontal: 0, vertical: 3.0),
          border: OutlineInputBorder(gapPadding: 3),
          isDense: true,
          isCollapsed: true,
        ),
        onChanged: (T? newValue) => onChanged!(newValue),
        items: items.map((T value) {
          return DropdownMenuItem<T>(
            value: value,
            child: Container(
              constraints: BoxConstraints(
                minWidth: 0,
                maxWidth: double.infinity,
              ),
              child: TextView(
                value.toString(),
                style: TextStyle(color: Colors.grey, fontSize: 16),
              ),
            ),
          );
        }).toList(),
        icon: SizedBox.shrink(),
        iconSize: 0,
        
      ),
    );
  }
}

class TextView extends StatelessWidget {
  final String data;
  final TextStyle? style;
  final TextAlign? textAlign;
  final bool? autoSize;

  const TextView(
    this.data, {
    super.key,
    this.style,
    this.textAlign,
    this.autoSize = false,
  });

  @override
  Widget build(BuildContext context) {
    return Text(
      data,
      style: style,
      textAlign: textAlign,
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
    );
  }
}
